//
//  StatusImage.swift
//  微博项目
//
//  Created by admin on 16/3/12.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit

class StatusImage: UIImageView {

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */
    convenience init() {
        self.init(frame: CGRect.zero)
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.contentMode =  UIViewContentMode.ScaleAspectFill
        self.userInteractionEnabled = true
        self.clipsToBounds = true
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        let photosUrl = (self.superview as! StatusImagesView).status.pic_urls as! [Picture]
        var photos = NSMutableArray()
        for var photoUrl in photosUrl
        {
            let photo = IDMPhoto(URL: NSURL(string: photoUrl.thumbnail_pic.stringByReplacingOccurrencesOfString("thumbnail", withString: "large")))
            photos.addObject(photo)
        }
        let broswer = IDMPhotoBrowser(photos: photos as [AnyObject])
        let currentController = (UIApplication.sharedApplication().keyWindow?.rootViewController as! JinTabbarController).selectedViewController
        currentController?.presentViewController(broswer, animated: true, completion: nil)
    }
}
